package com.ai.chinamobileai.controller;


import com.ai.chinamobileai.dto.ChatDTO;
import com.ai.chinamobileai.service.ChatService;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;

/**
 * @author
 * @version V1.0
 * @date 2025-04-20 10:22
 */
@RestController
@RequestMapping("/chat")
@RequiredArgsConstructor
public class ChatController {

    private final ChatService chatService;

    private final VectorStore vectorStore;


//    /**
//     * 搜索向量数据库
//     *
//     * @param query 搜索关键字
//     */
//    @PostMapping("/search")
//    public List<Document> search(@RequestParam("query") String query) {
//        return this.vectorStore.similaritySearch(SearchRequest.builder()
//                .query(query) // 设置查询条件
//                .topK(3) // 设置最多返回的文档数量
//                .build());
//    }



    /**
     * 流式聊天
     * @param chatDTO
     * @return
     */
    @PostMapping(value = "stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chatStream(@RequestBody ChatDTO chatDTO) {
        return chatService.chatStream(chatDTO);
    }
}
